<%@ page import="java.util.HashMap" %>
<%@ page import="static com.weavernorth.util.dateUtils.getNowDateTime" %>
<%@ page import="com.weavernorth.fadada.pojo.AccountRegistPoJo" %>
<%@ page import="com.weavernorth.util.MyCrypUtils" %>
<%@ page import="com.weavernorth.fadada.util.fadadaUtil" %>
<%@ page import="com.weaver.general.Util" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%
    String strSign = "";
    String timestamp = "";
    String biz_content = "";
    String str_response = "";
    String inStr="";
    String isSubmit = Util.null2String(request.getParameter("isSubmit"));
    //region [公共参数]
    timestamp = getNowDateTime();
    //配置接口路径
    HashMap<String, String> urlMap = new HashMap<>();
    urlMap.put("账户注册", "/account/register");
    urlMap.put("创建合同模板", "/contract/template/save");
    urlMap.put("查询模板", "/online-template/company/list");
    urlMap.put("模板填充", "/contract/generate");
    urlMap.put("查询客户编号", "/company/customer-id/list");
    String cType = "账户注册";
    //endregion
    if(isSubmit.equals("submit")) {

        if (cType.equals("账户注册")) {
            String strType = Util.null2String(request.getParameter("op_type"));//注册类型
            String strAccount = Util.null2String(request.getParameter("account"));//账户
            String strCompanyName = Util.null2String(request.getParameter("companyName"));//企业名称
            AccountRegistPoJo account_pojo = new AccountRegistPoJo();
            account_pojo.setType(strType);//注册类型：1:个人，2:企业
            account_pojo.setAccount(strAccount);
            account_pojo.setCompanyName(strCompanyName);
            biz_content = fadadaUtil.zhzc(account_pojo.getType(), account_pojo.getAccount(), account_pojo.getCompanyName());//账号注册
             inStr = "appId=" + fadadaUtil.appId + "&bizContent=" + biz_content + "&signType=" + fadadaUtil.signType + "&timestamp=" + timestamp;//待签名字符串
            try {
                strSign = MyCrypUtils.sh256Encrypt(inStr).toUpperCase();
                strSign = MyCrypUtils.sh256Encrypt(strSign + fadadaUtil.appkey).toUpperCase();
                strSign = MyCrypUtils.Base64Encode((strSign).getBytes());
            } catch (Exception ex) {
                System.out.println("sha256异常,异常信息：" + ex.toString());
            }

            HashMap<String, Object> params = fadadaUtil.getParams(timestamp,strSign, biz_content);
            System.out.println("参数：" + params.toString());
            str_response = fadadaUtil.sedDataTofdd(urlMap.get("账户注册"), params);
            System.out.println("账户注册结果：" + str_response);
        }
    }
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>账户注册</title>
    <script src="/js/jquery/jquery_wev8.js"></script>
    <script type="text/javascript">
        function checkSubmit() {
            if(frm.op_type.value==""){
                alert("请选择注册类型！");
                return;
            }
            if(frm.account.value==""){
                alert("请填写账户！");
                return;
            }
            if(frm.companyName.value==""){
                alert("请填写企业名称！");
                return;
            }
            frm.isSubmit.value="submit";
            frm.submit();

        }
    </script>
</head>
<body>
<h1>账户注册</h1>
<form name="frm" method="post" action="accountRegister.jsp" >
    <input type="hidden" name="isSubmit" value="">
    <div style="margin: auto">
        <table>
            <tr>
                <td>注册类型:</td>
                <td>
                    <select name="op_type">
                        <option value="1">个人</option>
                        <option value="2">企业</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>账号：</td>
                <td><input type="text" name="account" id="account"/></td>
            </tr>
<%--            <tr>--%>
<%--                <td>企业管理员客户编号：</td>--%>
<%--                <td><input type="text" name="adminAccountId" id="adminAccountId"/></td>--%>
<%--            </tr>--%>
            <tr>
                <td>企业名称：</td>
                <td><input type="text" name="companyName" id="companyName"/></td>
            </tr>
        </table>
    </div>
    <input type="submit"  value="注册" onclick="checkSubmit()"/>
    <div>
        <p>接口返回数据：<%=str_response%></p>
    </div>
</form>
</body>
</html>